package com.ray.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.ray.bean.BomOrderBusinessListBean;
import com.ray.bean.BomOrderBusinessTitleBean;
import com.ray.bean.BomOrderLevelRank;
import com.ray.bean.BomOrderListBean;
import com.ray.bean.BomOrderTitleBean;
import com.ray.bean.BomToCreateOrderListBean;
import com.ray.bean.DifficultLevelRateBean;
import com.ray.bean.MyApplyBean;
import com.ray.bean.MyApplyForBomBean;
import com.ray.bean.WasteRateBean;
import com.ray.exception.ServiceException;
import com.ray.service.OrderCreateForBomOrderService;
import com.ray.util.RequestUtil;
import com.ray.util.ResponseUtil;

import net.sf.json.JSON;
import net.sf.json.JSONArray;

/**
 *Bom订单
 * @author Shensg
 * 2018年1月24日
 */

@SuppressWarnings("unused")
@RestController
@RequestMapping("/createOrderForBomOrder")
public class OrderCreateForBomOrderController {
	
	@Autowired
	OrderCreateForBomOrderService orderCreateForBomOrderService;
	
	//损耗表列表
	@RequestMapping("/getWasteRateList")
	public Map getWasteRateList(WasteRateBean wasteRateBean , HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		return ResponseUtil.ResponseResult(orderCreateForBomOrderService.getWasteRateList(wasteRateBean,map));
	}  
	//损耗表新增
	@RequestMapping("/saveWasteRate")
	public Map saveWasteRate(WasteRateBean wasteRateBean , HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		orderCreateForBomOrderService.saveWasteRate(wasteRateBean,map);
		return ResponseUtil.ResponseResult("保存成功");
	}
	//损耗表新增
	@RequestMapping("/saveWasteRateForBomSelf")
	public Map saveWasteRateForBomSelf(HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		String dataStr = map.get("dataStr").toString();
		List<WasteRateBean> wasteRateBeans = JSONObject.parseArray(dataStr , WasteRateBean.class);
		orderCreateForBomOrderService.saveWasteRateForBomSelf(wasteRateBeans,map);
		return ResponseUtil.ResponseResult("保存成功");
	}
	@RequestMapping("/getWasteRateForBomSelf")
	public Map getWasteRateForBomSelf(WasteRateBean wasteRateBean , HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		return ResponseUtil.ResponseResult(orderCreateForBomOrderService.getWasteRateForBomSelf(wasteRateBean,map));
	}
	//损耗表修改
	@RequestMapping("/updateWasteRate")
	public Map updateWasteRate(WasteRateBean wasteRateBean , HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		orderCreateForBomOrderService.updateWasteRate(wasteRateBean,map);
		return ResponseUtil.ResponseResult("数据更新成功");
	}
	//损耗表单条数据获取
	@RequestMapping("/getWasteRateById")
	public Map getWasteRateById(WasteRateBean wasteRateBean , HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		return ResponseUtil.ResponseResult(orderCreateForBomOrderService.getWasteRateById(wasteRateBean,map));

	}
	
	//难易度列表difficult 
	@RequestMapping("/getDifficultLevelRateList")
	public Map getDifficultLevelRateList(DifficultLevelRateBean difficultLevelBean , HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		return ResponseUtil.ResponseResult(orderCreateForBomOrderService.getDifficultLevelList(difficultLevelBean,map));
	} 
	//难易度新增
	@RequestMapping("/saveDifficultLevelRate")
	public Map saveDifficultLevelRate(DifficultLevelRateBean difficultLevelBean , HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		orderCreateForBomOrderService.saveDifficultLevelRate(difficultLevelBean,map);
		return ResponseUtil.ResponseResult("保存成功");
	}
	//难易度修改 
	@RequestMapping("/updateDifficultLevelRate")
	public Map updateDifficultLevelRate(DifficultLevelRateBean difficultLevelBean , HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		orderCreateForBomOrderService.updateDifficultLevelRate(difficultLevelBean,map);
		return ResponseUtil.ResponseResult("数据更新成功");
	}
	
	//难易度单条数据获取
	@RequestMapping("/getDifficultLevelRateById")
	public Map getDifficultLevelRateById(DifficultLevelRateBean difficultLevelBean , HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		return ResponseUtil.ResponseResult(orderCreateForBomOrderService.getDifficultLevelRateById(difficultLevelBean,map));

	}
	
	//bom清单列表
	@RequestMapping("/getBomOrderTitleList")
	public Map getBomOrderTitleList(BomOrderTitleBean bomOrderTitleBean , HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		return ResponseUtil.ResponseResult(orderCreateForBomOrderService.getBomOrderTitleList(bomOrderTitleBean,map));
	}
	
	//bom清单新增
	@RequestMapping("/saveBomOrder")
	public Map saveBomOrder(BomOrderListBean bomOrderListBean, HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		String dataStr = map.get("dataStr").toString();
		bomOrderListBean = JSONObject.toJavaObject(JSONObject.parseObject(dataStr), BomOrderListBean.class);
		BomOrderTitleBean retTitleBean = orderCreateForBomOrderService.saveBomOrder(bomOrderListBean,map);
		return ResponseUtil.ResponseResult(retTitleBean);
	}
	//bom清单修改(未审核)
	@RequestMapping("/updateBomOrder")
	public Map updateBomOrder(BomOrderListBean bomOrderListBean, HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		String dataStr = map.get("dataStr").toString();
		bomOrderListBean = JSONObject.toJavaObject(JSONObject.parseObject(dataStr), BomOrderListBean.class);
		BomOrderTitleBean retTitleBean = orderCreateForBomOrderService.updateBomOrder(bomOrderListBean,map);
		return ResponseUtil.ResponseResult(retTitleBean);
	}
	//bom清单 审核
	@RequestMapping("/updateBomOrderStatus")
	public Map updateBomOrderStatus(BomOrderTitleBean bomOrderTitleBean, HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		orderCreateForBomOrderService.updateBomOrderStatus(bomOrderTitleBean,map);
		return ResponseUtil.ResponseResult("更新成功");
	}
	//bom清单单条数据获取
	@RequestMapping("/getBomOrderById")
	public Map getBomOrderDetailById(BomOrderTitleBean bomOrderTitleBean, HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		return ResponseUtil.ResponseResult(orderCreateForBomOrderService.getBomOrderDetailById(bomOrderTitleBean,map));
	}
	//TD bom清单申请修改(审核之后)
	@RequestMapping("/saveBomOrderForApply")
	public Map saveBomOrderForApply(BomOrderListBean bomOrderListBean, HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		String dataStr = map.get("dataStr").toString();
		bomOrderListBean = JSONObject.toJavaObject(JSONObject.parseObject(dataStr), BomOrderListBean.class);
		BomOrderTitleBean retTitleBean = orderCreateForBomOrderService.saveBomOrderForApply(bomOrderListBean,map);
		return ResponseUtil.ResponseResult(retTitleBean);
	}
	//TD bom清单申请修改 审核时数据查看
	@RequestMapping("/getBomOrderByApplyIdForApply")
	public Map getBomOrderByApplyIdForApply(BomOrderTitleBean bomOrderTitleBean, HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		return ResponseUtil.ResponseResult(orderCreateForBomOrderService.getBomOrderByApplyIdForApply(bomOrderTitleBean,map));
	}
	//TD bom清单申请修改 审核
	@RequestMapping("/updateBomOrderForApply")
	public Map updateBomOrderForApply(MyApplyForBomBean applyBean, HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		orderCreateForBomOrderService.updateBomOrderForApply(applyBean,map);
		return ResponseUtil.ResponseResult("审核成功");
	}
	//商务订单列表
	@RequestMapping("/getBomOrderBusinessList")
	public Map getBomOrderBusinessList(BomOrderBusinessTitleBean bomOrderBusinessTitleBean, HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		return ResponseUtil.ResponseResult(orderCreateForBomOrderService.getBomOrderBusinessList(bomOrderBusinessTitleBean,map));
	}
	//商务订单新增
	@RequestMapping("/saveBomOrderBusiness")
	public Map saveBomOrderBusiness( HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		String dataStr = map.get("dataStr").toString();
		BomOrderBusinessListBean bomOrderBusinessListBean = JSONObject.toJavaObject(JSONObject.parseObject(dataStr), BomOrderBusinessListBean.class);
		BomOrderBusinessTitleBean businessTitleBean = orderCreateForBomOrderService.saveBomOrderBusiness(bomOrderBusinessListBean,map);
		return ResponseUtil.ResponseResult(businessTitleBean);
	}
	//商务订单修改(未审核的时候)
	@RequestMapping("/updateBomOrderBusiness")
	public Map updateBomOrderBusiness (HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		String dataStr = map.get("dataStr").toString();
		BomOrderBusinessListBean bomOrderBusinessListBean = JSONObject.toJavaObject(JSONObject.parseObject(dataStr), BomOrderBusinessListBean.class);
		BomOrderBusinessTitleBean businessTitleBean = orderCreateForBomOrderService.updateBomOrderBusiness(bomOrderBusinessListBean,map);
		return ResponseUtil.ResponseResult(businessTitleBean);
	}
	//商务订单 审核
	@RequestMapping("/updateBomOrderBusinessStatus")
	public Map updateBomOrderBusinessStatus(BomOrderBusinessTitleBean bomOrderBusinessTitleBean, HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		orderCreateForBomOrderService.updateBomOrderBusinessStatus(bomOrderBusinessTitleBean,map);
		return ResponseUtil.ResponseResult("更新成功");
	}
	//商务订单单条数据获取
	@RequestMapping("/getBomOrderBussinessById")
	public Map getBomOrderBussinessById(BomOrderBusinessTitleBean bomOrderBusinessTitleBean, HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		return ResponseUtil.ResponseResult(orderCreateForBomOrderService.getBomOrderBusinessDetailById(bomOrderBusinessTitleBean,map));
	}
	//TD 商务订单申请修改 审核后
	@RequestMapping("/saveBomOrderBusinessApply")
	public Map saveBomOrderBusinessApply( HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		String dataStr = map.get("dataStr").toString();
		BomOrderBusinessListBean bomOrderBusinessListBean = JSONObject.toJavaObject(JSONObject.parseObject(dataStr), BomOrderBusinessListBean.class);
		BomOrderBusinessTitleBean businessTitleBean = orderCreateForBomOrderService.saveBomOrderBusinessApply(bomOrderBusinessListBean,map);
		return ResponseUtil.ResponseResult(businessTitleBean);
	}
	
	//TD 商务订单申请修改 审核时数据查看
	@RequestMapping("/getBomOrderBussinessByIdForApply")
	public Map getBomOrderBussinessByIdForApply(BomOrderBusinessTitleBean bomOrderBusinessTitleBean, HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		return ResponseUtil.ResponseResult(orderCreateForBomOrderService.getBomOrderBusinessDetailByIdForApply(bomOrderBusinessTitleBean,map));
	}
	//TD 商务订单申请修改 审核
	@RequestMapping("/updateBomOrderBussinessForApply")
	public Map updateBomOrderBussinessForApply(MyApplyForBomBean applyBean, HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		orderCreateForBomOrderService.updateBomOrderBussinessForApply(applyBean,map);
		return ResponseUtil.ResponseResult("审核成功");
	}
	
	
	//TD 模板订单修改
	@RequestMapping("/updateSystemTableConfigForBomOrder")
	public Map updateSystemTableConfigForBomOrder(HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		orderCreateForBomOrderService.updateSystemTableConfigForBomOrder(map);
		return ResponseUtil.ResponseResult("数据更新成功");
	}
	//TD 模板订单获取
	@RequestMapping("/getSystemTableConfigForBomOrder")
	public Map getSystemTableConfigForBomOrder(HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		return ResponseUtil.ResponseResult(orderCreateForBomOrderService.getSystemTableConfigForBomOrder(map));
	}
	//TD 模板订单修改 for apply
	@RequestMapping("/updateSystemTableConfigForBomOrderForApply")
	public Map updateSystemTableConfigForBomOrderForApply(HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		orderCreateForBomOrderService.updateSystemTableConfigForBomOrderForApply(map);
		return ResponseUtil.ResponseResult("数据更新成功");
	}
	//TD 模板订单获取  for apply
	@RequestMapping("/getSystemTableConfigForBomOrderForApply")
	public Map getSystemTableConfigForBomOrderForApply(HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		return ResponseUtil.ResponseResult(orderCreateForBomOrderService.getSystemTableConfigForBomOrderForApply(map));
	}
	//TD bom十种层级分类列表
	@RequestMapping("/getLevelRankList")
	public Map getLevelRankList(HttpServletRequest request,BomOrderLevelRank bean) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		return ResponseUtil.ResponseResult(orderCreateForBomOrderService.getLevelRankList(bean,map));
	}
	
	//TD bom十种层级分类列表
	@RequestMapping("/updateLevelRank")
	public Map updateLevelRank(HttpServletRequest request,BomOrderLevelRank bean) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		orderCreateForBomOrderService.updateLevelRank(bean,map);
		return ResponseUtil.ResponseResult("修改成功");
	}
	
	//TD bob十种层级分类列表
	@RequestMapping("/saveLevelRank")
	public Map saveLevelRank(HttpServletRequest request,BomOrderLevelRank bean) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		orderCreateForBomOrderService.saveLevelRank(bean,map);
		return ResponseUtil.ResponseResult("保存成功");
	}
	
	@RequestMapping("/saveOrderByBomOrder")
	public Map saveOrderByBomOrder(HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		String dataStr = map.get("dataStr").toString();
		BomToCreateOrderListBean bomToCreateOrderListBean = JSONObject.toJavaObject(JSONObject.parseObject(dataStr), BomToCreateOrderListBean.class);
		orderCreateForBomOrderService.saveOrderByBomOrder(bomToCreateOrderListBean,map);
		return ResponseUtil.ResponseResult("保存成功");
	}
	
	@RequestMapping("/getOrderBySysOrderNo")
	public Map getOrderBySysOrderNo(HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		String sysOrderNo = map.get("sysOrderNo").toString();
		BomToCreateOrderListBean bomToCreateOrderListBean = orderCreateForBomOrderService.getOrderBySysOrderNo(sysOrderNo,map);
		return ResponseUtil.ResponseResult(bomToCreateOrderListBean);
	}
	
	@RequestMapping("/saveOrderInfoForApply")
	public Map saveOrderInfo(HttpServletRequest request) throws IOException, ServiceException  {  
		Map<String, Object> map=RequestUtil.getRequestAllParam(request);
		String dataStr = map.get("dataStr").toString();
		BomToCreateOrderListBean bomToCreateOrderListBean = JSONObject.toJavaObject(JSONObject.parseObject(dataStr), BomToCreateOrderListBean.class);
		Boolean isSave = orderCreateForBomOrderService.saveOrderInfoForApply(bomToCreateOrderListBean,map);
        return ResponseUtil.ResponseResult((isSave)?"保存成功":"保存失败");
	}
	
	@RequestMapping("/getApplyOrder")
	public Map getApplyOrder(HttpServletRequest request) throws IOException, ServiceException  {  
		Map map=RequestUtil.getRequestAllParam(request);
		String sysOrderNo = map.get("sysOrderNo").toString();
		String applyId = map.get("applyId").toString();
		BomToCreateOrderListBean bomToCreateOrderListBean = orderCreateForBomOrderService.getApplyOrder(sysOrderNo,applyId,map);
		return ResponseUtil.ResponseResult(bomToCreateOrderListBean);
	}
	
	@RequestMapping("/getBomInfoForOpen")
	public Map getBomInfoForOpen(HttpServletRequest request) throws IOException, ServiceException  {  
		Map params=RequestUtil.getRequestAllParamNotLogin(request);
		return ResponseUtil.ResponseResult(orderCreateForBomOrderService.getBomInfoForOpen(params));
	}
}
